package list.ittest.work.C_Service;

import list.ittest.work.D_Dao.StudentDao;
import list.ittest.work.E_Domain.Student;

import java.util.ArrayList;

public class StudentService {
    //添加学生
    StudentDao sd = new StudentDao();

    public void addStudent(Student stu) {
        sd.addStudent(stu);
    }

    public ArrayList<Student> lookStudent() {
        ArrayList<Student> list = sd.lookStudent();
        return list;
    }

    public boolean deleteStudent(String id) {
        ArrayList<Student> list = sd.lookStudent();
        for (int i = 0; i < list.size(); i++) {
            Student s = list.get(i);
            if (s.getId().equals(id)) {
                sd.deleteStudent(i);
                return true;
            }
        }
        return false;
    }

    public boolean cheakId(String id) {
        ArrayList<Student> list = sd.lookStudent();
        for (int i = 0; i < list.size(); i++) {
            Student s = list.get(i);
            if (s.getId().equals(id)) {
                return false;
            }
        }
        return true;
    }

    public void updateStudent(Student s) {
        ArrayList<Student> list = sd.lookStudent();
        for (int i = 0; i < list.size(); i++) {
            Student stu = list.get(i);
            if (stu.getId().equals(s.getId())) {
                sd.updateStudent(i,s);
            }
        }
    }
}